/*
 * MIT License
 *
 * Copyright (c) 2023 北京凯特伟业科技有限公司
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.je.common.base.document;

import org.apache.commons.lang3.StringUtils;

/**
 * 文件后缀对应ContentType枚举
 *
 * @author wangmm@ketr.com.cn
 * @date 2019/10/14
 */
public enum ContentTypeSuffixEnum {
    /**
     * 文件后缀对应ContentType
     */
    S_001("001", "application/x-001"),
    S_301("301", "application/x-301"),
    S_323("323", "text/h323"),
    S_906("906", "application/x-906"),
    S_907("907", "drawing/907"),
    S_a11("a11", "application/x-a11"),
    S_acp("acp", "audio/x-mei-aac"),
    S_ai("ai", "application/postscript"),
    S_aif("aif", "audio/aiff"),
    S_aifc("aifc", "audio/aiff"),
    S_aiff("aiff", "audio/aiff"),
    S_anv("anv", "application/x-anv"),
    S_asa("asa", "text/asa"),
    S_asf("asf", "video/x-ms-asf"),
    S_asp("asp", "text/asp"),
    S_asx("asx", "video/x-ms-asf"),
    S_au("au", "audio/basic"),
    S_avi("avi", "video/avi"),
    S_awf("awf", "application/vnd.adobe.workflow"),
    S_biz("biz", "text/xml"),
    S_bmp("bmp", "application/x-bmp"),
    S_bot("bot", "application/x-bot"),
    S_c4t("c4t", "application/x-c4t"),
    S_c90("c90", "application/x-c90"),
    S_cal("cal", "application/x-cals"),
    S_cat("cat", "application/vnd.ms-pki.seccat"),
    S_cdf("cdf", "application/x-netcdf"),
    S_cdr("cdr", "application/x-cdr"),
    S_cel("cel", "application/x-cel"),
    S_cer("cer", "application/x-x509-ca-cert"),
    S_cg4("cg4", "application/x-g4"),
    S_cgm("cgm", "application/x-cgm"),
    S_cit("cit", "application/x-cit"),
    S_class("class", "java/*"),
    S_cml("cml", "text/xml"),
    S_cmp("cmp", "application/x-cmp"),
    S_cmx("cmx", "application/x-cmx"),
    S_cot("cot", "application/x-cot"),
    S_crl("crl", "application/pkix-crl"),
    S_crt("crt", "application/x-x509-ca-cert"),
    S_csi("csi", "application/x-csi"),
    S_css("css", "text/css"),
    S_cut("cut", "application/x-cut"),
    S_dbf("dbf", "application/x-dbf"),
    S_dbm("dbm", "application/x-dbm"),
    S_dbx("dbx", "application/x-dbx"),
    S_dcd("dcd", "text/xml"),
    S_dcx("dcx", "application/x-dcx"),
    S_der("der", "application/x-x509-ca-cert"),
    S_dgn("dgn", "application/x-dgn"),
    S_dib("dib", "application/x-dib"),
    S_dll("dll", "application/x-msdownload"),
    S_doc("doc", "application/msword"),
    S_dot("dot", "application/msword"),
    S_drw("drw", "application/x-drw"),
    S_dtd("dtd", "text/xml"),
    //    S_dwf("dwf","Model/vnd.dwf"),
    S_dwf("dwf", "application/x-dwf"),
    S_dwg("dwg", "application/x-dwg"),
    S_dxb("dxb", "application/x-dxb"),
    S_dxf("dxf", "application/x-dxf"),
    S_edn("edn", "application/vnd.adobe.edn"),
    S_emf("emf", "application/x-emf"),
    S_eml("eml", "message/rfc822"),
    S_ent("ent", "text/xml"),
    S_epi("epi", "application/x-epi"),
    S_eps("eps", "application/x-ps"),
    //    S_eps("eps","application/postscript"),
    S_etd("etd", "application/x-ebx"),
    S_exe("exe", "application/x-msdownload"),
    S_fax("fax", "image/fax"),
    S_fdf("fdf", "application/vnd.fdf"),
    S_fif("fif", "application/fractals"),
    S_fo("fo", "text/xml"),
    S_frm("frm", "application/x-frm"),
    S_g4("g4", "application/x-g4"),
    S_gbr("gbr", "application/x-gbr"),
    S_("", "application/x-"),
    S_gif("gif", "image/gif"),
    S_gl2("gl2", "application/x-gl2"),
    S_gp4("gp4", "application/x-gp4"),
    S_hgl("hgl", "application/x-hgl"),
    S_hmr("hmr", "application/x-hmr"),
    S_hpg("hpg", "application/x-hpgl"),
    S_hpl("hpl", "application/x-hpl"),
    S_hqx("hqx", "application/mac-binhex40"),
    S_hrf("hrf", "application/x-hrf"),
    S_hta("hta", "application/hta"),
    S_htc("htc", "text/x-component"),
    S_htm("htm", "text/html"),
    S_html("html", "text/html"),
    S_htt("htt", "text/webviewhtml"),
    S_htx("htx", "text/html"),
    S_icb("icb", "application/x-icb"),
    S_ico("ico", "image/x-icon"),
    //    S_ico("ico","application/x-ico"),
    S_iff("iff", "application/x-iff"),
    S_ig4("ig4", "application/x-g4"),
    S_igs("igs", "application/x-igs"),
    S_iii("iii", "application/x-iphone"),
    S_img("img", "application/x-img"),
    S_ins("ins", "application/x-internet-signup"),
    S_isp("isp", "application/x-internet-signup"),
    S_IVF("IVF", "video/x-ivf"),
    S_java("java", "java/*"),
    S_jfif("jfif", "image/jpeg"),
    S_jpe("jpe", "image/jpeg"),
    //    S_jpe("jpe","application/x-jpe"),
    S_jpeg("jpeg", "image/jpeg"),
    S_jpg("jpg", "image/jpeg"),
    //    S_jpg("jpg","application/x-jpg"),
    S_js("js", "application/x-javascript"),
    S_jsp("jsp", "text/html"),
    S_la1("la1", "audio/x-liquid-file"),
    S_lar("lar", "application/x-laplayer-reg"),
    S_latex("latex", "application/x-latex"),
    S_lavs("lavs", "audio/x-liquid-secure"),
    S_lbm("lbm", "application/x-lbm"),
    S_lmsff("lmsff", "audio/x-la-lms"),
    S_ls("ls", "application/x-javascript"),
    S_ltr("ltr", "application/x-ltr"),
    S_m1v("m1v", "video/x-mpeg"),
    S_m2v("m2v", "video/x-mpeg"),
    S_m3u("m3u", "audio/mpegurl"),
    S_m4e("m4e", "video/mpeg4"),
    S_mac("mac", "application/x-mac"),
    S_man("man", "application/x-troff-man"),
    S_math("math", "text/xml"),
    //    S_mdb("mdb","application/msaccess"),
    S_mdb("mdb", "application/x-mdb"),
    S_mfp("mfp", "application/x-shockwave-flash"),
    S_mht("mht", "message/rfc822"),
    S_mhtml("mhtml", "message/rfc822"),
    S_mi("mi", "application/x-mi"),
    S_mid("mid", "audio/mid"),
    S_midi("midi", "audio/mid"),
    S_mil("mil", "application/x-mil"),
    S_mml("mml", "text/xml"),
    S_mnd("mnd", "audio/x-musicnet-download"),
    S_mns("mns", "audio/x-musicnet-stream"),
    S_mocha("mocha", "application/x-javascript"),
    S_movie("movie", "video/x-sgi-movie"),
    S_mp1("mp1", "audio/mp1"),
    S_mp2("mp2", "audio/mp2"),
    S_mp2v("mp2v", "video/mpeg"),
    S_mp3("mp3", "audio/mp3"),
    S_mp4("mp4", "video/mpeg4"),
    S_mpa("mpa", "video/x-mpg"),
    S_mpd("mpd", "application/vnd.ms-project"),
    S_mpe("mpe", "video/x-mpeg"),
    S_mpeg("mpeg", "video/mpg"),
    S_mpg("mpg", "video/mpg"),
    S_mpga("mpga", "audio/rn-mpeg"),
    S_mpp("mpp", "application/vnd.ms-project"),
    S_mps("mps", "video/x-mpeg"),
    S_mpt("mpt", "application/vnd.ms-project"),
    S_mpv("mpv", "video/mpg"),
    S_mpv2("mpv2", "video/mpeg"),
    S_mpw("mpw", "application/vnd.ms-project"),
    S_mpx("mpx", "application/vnd.ms-project"),
    S_mtx("mtx", "text/xml"),
    S_mxp("mxp", "application/x-mmxp"),
    S_net("net", "image/pnetvue"),
    S_nrf("nrf", "application/x-nrf"),
    S_nws("nws", "message/rfc822"),
    S_odc("odc", "text/x-ms-odc"),
    S_out("out", "application/x-out"),
    S_p10("p10", "application/pkcs10"),
    S_p12("p12", "application/x-pkcs12"),
    S_p7b("p7b", "application/x-pkcs7-certificates"),
    S_p7c("p7c", "application/pkcs7-mime"),
    S_p7m("p7m", "application/pkcs7-mime"),
    S_p7r("p7r", "application/x-pkcs7-certreqresp"),
    S_p7s("p7s", "application/pkcs7-signature"),
    S_pc5("pc5", "application/x-pc5"),
    S_pci("pci", "application/x-pci"),
    S_pcl("pcl", "application/x-pcl"),
    S_pcx("pcx", "application/x-pcx"),
    S_pdf("pdf", "application/pdf"),
    S_pdx("pdx", "application/vnd.adobe.pdx"),
    S_pfx("pfx", "application/x-pkcs12"),
    S_pgl("pgl", "application/x-pgl"),
    S_pic("pic", "application/x-pic"),
    S_pko("pko", "application/vnd.ms-pki.pko"),
    S_pl("pl", "application/x-perl"),
    S_plg("plg", "text/html"),
    S_pls("pls", "audio/scpls"),
    S_plt("plt", "application/x-plt"),
    S_png("png", "image/png"),
    //    S_png("png","application/x-png"),
    S_pot("pot", "application/vnd.ms-powerpoint"),
    S_ppa("ppa", "application/vnd.ms-powerpoint"),
    S_ppm("ppm", "application/x-ppm"),
    S_pps("pps", "application/vnd.ms-powerpoint"),
    S_ppt("ppt", "application/vnd.ms-powerpoint"),
    //    S_ppt("ppt","application/x-ppt"),
    S_pr("pr", "application/x-pr"),
    S_prf("prf", "application/pics-rules"),
    S_prn("prn", "application/x-prn"),
    S_prt("prt", "application/x-prt"),
    S_ps("ps", "application/x-ps"),
    //    S_ps("ps","application/postscript"),
    S_ptn("ptn", "application/x-ptn"),
    S_pwz("pwz", "application/vnd.ms-powerpoint"),
    S_r3t("r3t", "text/vnd.rn-realtext3d"),
    S_ra("ra", "audio/vnd.rn-realaudio"),
    S_ram("ram", "audio/x-pn-realaudio"),
    S_ras("ras", "application/x-ras"),
    S_rat("rat", "application/rat-file"),
    S_rdf("rdf", "text/xml"),
    S_rec("rec", "application/vnd.rn-recording"),
    S_red("red", "application/x-red"),
    S_rgb("rgb", "application/x-rgb"),
    S_rjs("rjs", "application/vnd.rn-realsystem-rjs"),
    S_rjt("rjt", "application/vnd.rn-realsystem-rjt"),
    S_rlc("rlc", "application/x-rlc"),
    S_rle("rle", "application/x-rle"),
    S_rm("rm", "application/vnd.rn-realmedia"),
    S_rmf("rmf", "application/vnd.adobe.rmf"),
    S_rmi("rmi", "audio/mid"),
    S_rmj("rmj", "application/vnd.rn-realsystem-rmj"),
    S_rmm("rmm", "audio/x-pn-realaudio"),
    S_rmp("rmp", "application/vnd.rn-rn_music_package"),
    S_rms("rms", "application/vnd.rn-realmedia-secure"),
    S_rmvb("rmvb", "application/vnd.rn-realmedia-vbr"),
    S_rmx("rmx", "application/vnd.rn-realsystem-rmx"),
    S_rnx("rnx", "application/vnd.rn-realplayer"),
    S_rp("rp", "image/vnd.rn-realpix"),
    S_rpm("rpm", "audio/x-pn-realaudio-plugin"),
    S_rsml("rsml", "application/vnd.rn-rsml"),
    S_rt("rt", "text/vnd.rn-realtext"),
    S_rtf("rtf", "application/msword"),
    //    S_rtf("rtf","application/x-rtf"),
    S_rv("rv", "video/vnd.rn-realvideo"),
    S_sam("sam", "application/x-sam"),
    S_sat("sat", "application/x-sat"),
    S_sdp("sdp", "application/sdp"),
    S_sdw("sdw", "application/x-sdw"),
    S_sit("sit", "application/x-stuffit"),
    S_slb("slb", "application/x-slb"),
    S_sld("sld", "application/x-sld"),
    S_slk("slk", "drawing/x-slk"),
    S_smi("smi", "application/smil"),
    S_smil("smil", "application/smil"),
    S_smk("smk", "application/x-smk"),
    S_snd("snd", "audio/basic"),
    S_sol("sol", "text/plain"),
    S_sor("sor", "text/plain"),
    S_spc("spc", "application/x-pkcs7-certificates"),
    S_spl("spl", "application/futuresplash"),
    S_spp("spp", "text/xml"),
    S_ssm("ssm", "application/streamingmedia"),
    S_sst("sst", "application/vnd.ms-pki.certstore"),
    S_stl("stl", "application/vnd.ms-pki.stl"),
    S_stm("stm", "text/html"),
    S_sty("sty", "application/x-sty"),
    S_svg("svg", "text/xml"),
    S_swf("swf", "application/x-shockwave-flash"),
    S_tdf("tdf", "application/x-tdf"),
    S_tg4("tg4", "application/x-tg4"),
    S_tga("tga", "application/x-tga"),
    S_tif("tif", "image/tiff"),
    //    S_tif("tif","application/x-tif"),
    S_tiff("tiff", "image/tiff"),
    S_tld("tld", "text/xml"),
    S_top("top", "drawing/x-top"),
    S_torrent("torrent", "application/x-bittorrent"),
    S_tsd("tsd", "text/xml"),
    S_txt("txt", "text/plain"),
    S_uin("uin", "application/x-icq"),
    S_uls("uls", "text/iuls"),
    S_vcf("vcf", "text/x-vcard"),
    S_vda("vda", "application/x-vda"),
    S_vdx("vdx", "application/vnd.visio"),
    S_vml("vml", "text/xml"),
    S_vpg("vpg", "application/x-vpeg005"),
    //    S_vsd("vsd","application/vnd.visio"),
    S_vsd("vsd", "application/x-vsd"),
    S_vss("vss", "application/vnd.visio"),
    //    S_vst("vst","application/vnd.visio"),
    S_vst("vst", "application/x-vst"),
    S_vsw("vsw", "application/vnd.visio"),
    S_vsx("vsx", "application/vnd.visio"),
    S_vtx("vtx", "application/vnd.visio"),
    S_vxml("vxml", "text/xml"),
    S_wav("wav", "audio/wav"),
    S_wax("wax", "audio/x-ms-wax"),
    S_wb1("wb1", "application/x-wb1"),
    S_wb2("wb2", "application/x-wb2"),
    S_wb3("wb3", "application/x-wb3"),
    S_wbmp("wbmp", "image/vnd.wap.wbmp"),
    S_wiz("wiz", "application/msword"),
    S_wk3("wk3", "application/x-wk3"),
    S_wk4("wk4", "application/x-wk4"),
    S_wkq("wkq", "application/x-wkq"),
    S_wks("wks", "application/x-wks"),
    S_wm("wm", "video/x-ms-wm"),
    S_wma("wma", "audio/x-ms-wma"),
    S_wmd("wmd", "application/x-ms-wmd"),
    S_wmf("wmf", "application/x-wmf"),
    S_wml("wml", "text/vnd.wap.wml"),
    S_wmv("wmv", "video/x-ms-wmv"),
    S_wmx("wmx", "video/x-ms-wmx"),
    S_wmz("wmz", "application/x-ms-wmz"),
    S_wp6("wp6", "application/x-wp6"),
    S_wpd("wpd", "application/x-wpd"),
    S_wpg("wpg", "application/x-wpg"),
    S_wpl("wpl", "application/vnd.ms-wpl"),
    S_wq1("wq1", "application/x-wq1"),
    S_wr1("wr1", "application/x-wr1"),
    S_wri("wri", "application/x-wri"),
    S_wrk("wrk", "application/x-wrk"),
    S_ws("ws", "application/x-ws"),
    S_ws2("ws2", "application/x-ws"),
    S_wsc("wsc", "text/scriptlet"),
    S_wsdl("wsdl", "text/xml"),
    S_wvx("wvx", "video/x-ms-wvx"),
    S_xdp("xdp", "application/vnd.adobe.xdp"),
    S_xdr("xdr", "text/xml"),
    S_xfd("xfd", "application/vnd.adobe.xfd"),
    S_xfdf("xfdf", "application/vnd.adobe.xfdf"),
    S_xhtml("xhtml", "text/html"),
    S_xls("xls", "application/vnd.ms-excel"),
    //    S_xls("xls","application/x-xls"),
    S_xlw("xlw", "application/x-xlw"),
    S_xml("xml", "text/xml"),
    S_xpl("xpl", "audio/scpls"),
    S_xq("xq", "text/xml"),
    S_xql("xql", "text/xml"),
    S_xquery("xquery", "text/xml"),
    S_xsd("xsd", "text/xml"),
    S_xsl("xsl", "text/xml"),
    S_xslt("xslt", "text/xml"),
    S_xwd("xwd", "application/x-xwd"),
    S_x_b("x_b", "application/x-x_b"),
    S_sis("sis", "application/vnd.symbian.install"),
    S_sisx("sisx", "application/vnd.symbian.install"),
    S_x_t("x_t", "application/x-x_t"),
    S_ipa("ipa", "application/vnd.iphone"),
    S_apk("apk", "application/vnd.android.package-archive"),
    S_xap("xap", "application/x-silverlight-app"),
    S_zip("zip", "application/zip"),
    stream("", "application/octet-stream");
    String suffix;
    String contentType;

    private ContentTypeSuffixEnum(String suffix, String contentType) {
        this.suffix = suffix;
        this.contentType = contentType;
    }

    /**
     * 根据后缀获取ContentType
     *
     * @param suffix 后缀
     * @return java.lang.String
     */
    public static String contentType(String suffix) {
        if (StringUtils.isBlank(suffix)) {
            return ContentTypeSuffixEnum.stream.getContentType();
        }
        try {
            ContentTypeSuffixEnum e = ContentTypeSuffixEnum.valueOf("S_" + suffix);
            return e.getContentType();
        } catch (IllegalArgumentException e) {
            return ContentTypeSuffixEnum.stream.getContentType();
        }
    }

    public String getSuffix() {
        return suffix;
    }

    public String getContentType() {
        return contentType;
    }

}
